<?php 
## include required files
/*******************************/
require_once '../model/cms.php';
/*******************************/
## Create Objects
/*******************************/
$cmsObj = new Model_CMS();
/*******************************/

if($_GET['id']!=''&& $_GET['action']=='edit') {
	$submenu_id=base64_decode($_GET['id']);
	$smarty->assign('page', $_GET['page']);
	$cmsArray=$cmsObj->getSubmenuDetailsById($submenu_id);
	$smarty->assign('cmsArray', $cmsArray);
}
function strip_fck_strip_value($value) {
//	echo "value".$value;die();
  return preg_replace('/^(\<p\>(\&nbsp\;|(\s)*)\<\/p\>|\<br(\s\/)?\>)$/', '', $value);
}

if(isset($_POST['editcms_btn'])) 
{

	$var_submenu_content = strip_fck_strip_value($_POST['submenu_content']); 
	//print_R($var_submenu_content);die();
	## apply PHP validation for required filed
	if($var_submenu_content!= '') 
	{
		
		$submenuArray = array();		
		extract($_POST);	
		
		$submenuArray['submenu_title']   = return_post_value($submenu_title);
		$submenuArray['submenu_content'] = return_post_value($submenu_content);
		/*$submenuArray['meta_title']      = return_post_value($meta_title);
		$submenuArray['meta_keyword']    = return_post_value($meta_keyword);
		$submenuArray['meta_description']= return_post_value($meta_description);*/
		$cmsObj->editUserCmsById($submenuArray,$_POST['submenu_id']);
		$_SESSION['msg']="<div class='success_msg'><span>CMS detail updated successfully!</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=cms&page='.$_POST['page']);
		exit;
		
	} else {// php validation else
		$_SESSION['msg']="<div class='error_msg'><span> Sub menu title and Content can't be blank</span></div>";
	}
	// main if closed
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}


## Set active class variable for left menu
$smarty->assign('activeclass', 'cms');
$smarty->assign('mainmenu', '1');

## Unset all the objects created which are on this page
unset($cmsObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'cms/editcms.tpl');
unset($smarty);
?>